/**
 * Copyright (c) OpenSpug Organization. https://github.com/openspug/spug
 * Copyright (c) <spug.dev@gmail.com>
 * Released under the AGPL-3.0 License.
 */
import { observable } from "mobx";
import {Roles, UserList} from "../../../api/system/account/UserApi";

class Store {
  @observable records = [];
  @observable record = {};
  @observable isFetching = false;
  @observable formVisible = false;

  @observable f_name;
  @observable f_status;

  @observable roleFormVisible = false;

  //分配的角色
  @observable hasRoles = [];
  @observable allRoles = [];

  fetchRecords = () => {
    this.isFetching = true;
    UserList({page:1,pageSize:1000}).then(response => {
      this.records = response.data.list;
    }).finally(() => this.isFetching = false);
  };

  showForm = (info = {}) => {
    this.formVisible = true;
    this.record = info
  };

  showRoleForm = (record = {}) => {
    this.roleFormVisible = true;
    this.record = record;
  };

  initRoles = () => {
    Roles({id:this.record.id}).then(response => {
       if (response.data.code === 200){
         this.allRoles = response.data.allRoles;
         this.hasRoles = response.data.hasRoles;
       }
    })
  }
}

export default new Store()
